/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Strings;
/*     */ import com.google.common.collect.Iterables;
/*     */ import com.google.common.io.Closeables;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMailbox.Options;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.Element.Disposition;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.index.IndexStore;
/*     */ import com.zimbra.cs.index.MessageHit;
/*     */ import com.zimbra.cs.index.QueryInfo;
/*     */ import com.zimbra.cs.index.ResultsPager;
/*     */ import com.zimbra.cs.index.SearchParams;
/*     */ import com.zimbra.cs.index.SearchParams.Cursor;
/*     */ import com.zimbra.cs.index.SearchParams.ExpandResults;
/*     */ import com.zimbra.cs.index.SortBy;
/*     */ import com.zimbra.cs.index.ZimbraHit;
/*     */ import com.zimbra.cs.index.ZimbraQueryResults;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxIndex;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CacheToXML;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalendarCacheManager;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalendarData;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalendarItemData;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.cs.util.AccountUtil;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.mail.message.SearchRequest;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Search
/*     */   extends MailDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  77 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  78 */     Mailbox mbox = getRequestedMailbox(zsc);
/*  79 */     Account account = getRequestedAccount(zsc);
/*  80 */     OperationContext octxt = getOperationContext(zsc, context);
/*  81 */     fixBooleanRecipients(request);
/*  82 */     SearchRequest req = (SearchRequest)JaxbUtil.elementToJaxb(request);
/*  83 */     if (((Boolean)Objects.firstNonNull(req.getWarmup(), Boolean.valueOf(false))).booleanValue()) {
/*  84 */       mbox.index.getIndexStore().warmup();
/*  85 */       return zsc.createElement(MailConstants.SEARCH_RESPONSE);
/*     */     }
/*     */     
/*  88 */     SearchParams params = SearchParams.parse(req, zsc, account.getPrefMailInitialSearch());
/*  89 */     if (params.getLocale() == null) {
/*  90 */       params.setLocale(mbox.getAccount().getLocale());
/*     */     }
/*  92 */     if ((params.inDumpster()) && (params.getTypes().contains(MailItem.Type.CONVERSATION))) {
/*  93 */       throw ServiceException.INVALID_REQUEST("cannot search for conversations in dumpster", null);
/*     */     }
/*     */     Element response;
/*  96 */     if (LC.calendar_cache_enabled.booleanValue()) {
/*  97 */       List<String> apptFolderIds = getFolderIdListIfSimpleAppointmentsQuery(params, zsc);
/*  98 */       if (apptFolderIds != null) {
/*  99 */         Account authAcct = getAuthenticatedAccount(zsc);
/* 100 */         response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
/* 101 */         runSimpleAppointmentQuery(response, params, octxt, zsc, authAcct, mbox, apptFolderIds);
/* 102 */         return response;
/*     */       }
/*     */     }
/*     */     
/* 106 */     ZimbraQueryResults results = mbox.index.search(zsc.getResponseProtocol(), octxt, params);
/*     */     try
/*     */     {
/* 109 */       Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
/*     */       
/*     */ 
/* 112 */       response.addAttribute("sortBy", results.getSortBy().toString());
/* 113 */       putHits(zsc, octxt, response, results, params);
/* 114 */       return response;
/*     */     } finally {
/* 116 */       Closeables.closeQuietly(results);
/*     */     }
/*     */   }
/*     */   
/*     */   protected static void putInfo(Element response, ZimbraQueryResults results) {
/* 121 */     List<QueryInfo> qinfo = results.getResultInfo();
/* 122 */     Element qinfoElt; if (qinfo.size() > 0) {
/* 123 */       qinfoElt = response.addElement("info");
/* 124 */       for (QueryInfo inf : qinfo) {
/* 125 */         inf.toXml(qinfoElt);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void putHits(ZimbraSoapContext zsc, OperationContext octxt, Element el, ZimbraQueryResults results, SearchParams params)
/*     */     throws ServiceException
/*     */   {
/* 133 */     if ((params.getInlineRule() == SearchParams.ExpandResults.HITS) || (params.getInlineRule() == SearchParams.ExpandResults.FIRST_MSG) || (params.getInlineRule() == SearchParams.ExpandResults.HITS_OR_FIRST_MSG) || (params.getInlineRule() == SearchParams.ExpandResults.UNREAD) || (params.getInlineRule() == SearchParams.ExpandResults.UNREAD_FIRST) || (params.getInlineRule() == SearchParams.ExpandResults.U_OR_FIRST_MSG) || (params.getInlineRule() == SearchParams.ExpandResults.U1_OR_FIRST_MSG))
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 141 */       params.setInlineRule(SearchParams.ExpandResults.NONE);
/*     */     }
/*     */     
/* 144 */     ResultsPager pager = ResultsPager.create(results, params);
/* 145 */     if (params.getCursor() != null) {
/* 146 */       if (params.getCursor().isIncludeOffset()) {
/* 147 */         long offset = pager.getCursorOffset();
/* 148 */         if (offset >= 0L) {
/* 149 */           el.addAttribute("offset", offset);
/*     */         }
/*     */       }
/*     */     } else {
/* 153 */       el.addAttribute("offset", params.getOffset());
/*     */     }
/*     */     
/* 156 */     SearchResponse resp = new SearchResponse(zsc, octxt, el, params);
/* 157 */     resp.setIncludeMailbox(false);
/* 158 */     resp.setSortOrder(pager.getSortOrder());
/*     */     
/* 160 */     SearchParams.ExpandResults expandValue = params.getInlineRule();
/* 161 */     int hitNum = 0;
/* 162 */     while ((pager.hasNext()) && (resp.size() < params.getLimit())) {
/* 163 */       hitNum++;
/* 164 */       ZimbraHit hit = pager.getNextHit();
/* 165 */       if ((hit instanceof MessageHit))
/*     */       {
/*     */         boolean expand;
/*     */         
/*     */ 
/*     */         boolean expand;
/*     */         
/*     */ 
/* 173 */         if (expandValue == SearchParams.ExpandResults.NONE) {
/* 174 */           expand = false; } else { boolean expand;
/* 175 */           if (expandValue == SearchParams.ExpandResults.ALL) {
/* 176 */             expand = true; } else { boolean expand;
/* 177 */             if (expandValue == SearchParams.ExpandResults.FIRST) {
/* 178 */               expand = params.getOffset() <= 0;
/*     */             } else
/* 180 */               expand = expandValue.matches(hit.getParsedItemID());
/*     */           } }
/* 182 */         resp.add(hit, expand);
/*     */       } else {
/* 184 */         resp.add(hit);
/*     */       }
/*     */     }
/* 187 */     resp.addHasMore(pager.hasNext());
/* 188 */     resp.add(results.getResultInfo());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected List<String> getFolderIdListIfSimpleAppointmentsQuery(SearchParams params, ZimbraSoapContext zsc)
/*     */     throws ServiceException
/*     */   {
/* 202 */     Set<MailItem.Type> types = params.getTypes();
/* 203 */     if (types.size() != 1) {
/* 204 */       return null;
/*     */     }
/* 206 */     MailItem.Type type = (MailItem.Type)Iterables.getOnlyElement(types);
/* 207 */     if ((type != MailItem.Type.APPOINTMENT) && (type != MailItem.Type.TASK)) {
/* 208 */       return null;
/*     */     }
/*     */     
/* 211 */     if ((params.getCalItemExpandStart() == -1L) || (params.getCalItemExpandEnd() == -1L)) {
/* 212 */       return null;
/*     */     }
/*     */     
/* 215 */     if (params.getOffset() != 0) {
/* 216 */       return null;
/*     */     }
/*     */     
/* 219 */     SortBy sortBy = params.getSortBy();
/* 220 */     if ((sortBy != null) && (!sortBy.equals(SortBy.NONE))) {
/* 221 */       return null;
/*     */     }
/*     */     
/* 224 */     String queryString = Strings.nullToEmpty(params.getQueryString());
/* 225 */     queryString = queryString.toLowerCase();
/* 226 */     queryString = removeOuterParens(queryString);
/*     */     
/* 228 */     if (queryString.contains("and")) {
/* 229 */       return null;
/*     */     }
/* 231 */     String[] terms = queryString.split("\\s+or\\s+");
/* 232 */     List<String> folderIdStrs = new ArrayList();
/* 233 */     for (String term : terms) {
/* 234 */       term = term.trim();
/*     */       
/* 236 */       term = removeOuterParens(term);
/* 237 */       if (!term.startsWith("inid:")) {
/* 238 */         return null;
/*     */       }
/* 240 */       String folderId = term.substring(5);
/* 241 */       folderId = unquote(folderId);
/* 242 */       if (folderId.length() > 0) {
/* 243 */         folderIdStrs.add(folderId);
/*     */       }
/*     */     }
/* 246 */     return folderIdStrs;
/*     */   }
/*     */   
/*     */   private static String removeOuterParens(String str) {
/* 250 */     int len = str.length();
/* 251 */     if ((len > 2) && (str.charAt(0) == '(') && (str.charAt(len - 1) == ')'))
/* 252 */       str = str.substring(1, len - 1);
/* 253 */     return str;
/*     */   }
/*     */   
/*     */   private static String unquote(String str) {
/* 257 */     int len = str.length();
/* 258 */     if ((len > 2) && (str.charAt(0) == '\'') && (str.charAt(len - 1) == '\''))
/* 259 */       str = str.substring(1, len - 1);
/* 260 */     len = str.length();
/* 261 */     if ((len > 2) && (str.charAt(0) == '"') && (str.charAt(len - 1) == '"'))
/* 262 */       str = str.substring(1, len - 1);
/* 263 */     return str;
/*     */   }
/*     */   
/*     */   private static void runSimpleAppointmentQuery(Element parent, SearchParams params, OperationContext octxt, ZimbraSoapContext zsc, Account authAcct, Mailbox mbox, List<String> folderIdStrs) throws ServiceException
/*     */   {
/* 268 */     Set<MailItem.Type> types = params.getTypes();
/* 269 */     MailItem.Type type = types.size() == 1 ? (MailItem.Type)Iterables.getOnlyElement(types) : MailItem.Type.APPOINTMENT;
/*     */     
/* 271 */     if (params.getSortBy() != null) {
/* 272 */       parent.addAttribute("sortBy", params.getSortBy().toString());
/*     */     }
/* 274 */     parent.addAttribute("offset", params.getOffset());
/* 275 */     parent.addAttribute("more", false);
/*     */     
/* 277 */     List<ItemId> folderIids = new ArrayList(folderIdStrs.size());
/* 278 */     for (String folderIdStr : folderIdStrs) {
/* 279 */       folderIids.add(new ItemId(folderIdStr, zsc));
/*     */     }
/*     */     
/* 282 */     Provisioning prov = Provisioning.getInstance();
/* 283 */     MailboxManager mboxMgr = MailboxManager.getInstance();
/* 284 */     Server localServer = prov.getLocalServer();
/*     */     
/* 286 */     Map<Server, Map<String, List<Integer>>> groupedByServer = groupByServer(ItemId.groupFoldersByAccount(octxt, mbox, folderIids));
/*     */     
/*     */ 
/*     */ 
/* 290 */     if (LC.calendar_cache_enabled.booleanValue()) {
/* 291 */       CalSummaryCache calCache = CalendarCacheManager.getInstance().getSummaryCache();
/* 292 */       long rangeStart = params.getCalItemExpandStart();
/* 293 */       long rangeEnd = params.getCalItemExpandEnd();
/* 294 */       Iterator<Map.Entry<Server, Map<String, List<Integer>>>> serverIter = groupedByServer.entrySet().iterator();
/* 295 */       while (serverIter.hasNext()) {
/* 296 */         Map.Entry<Server, Map<String, List<Integer>>> serverMapEntry = (Map.Entry)serverIter.next();
/* 297 */         Map<String, List<Integer>> accountFolders = (Map)serverMapEntry.getValue();
/*     */         
/* 299 */         Iterator<Map.Entry<String, List<Integer>>> acctIter = accountFolders.entrySet().iterator();
/* 300 */         while (acctIter.hasNext()) {
/* 301 */           Map.Entry<String, List<Integer>> acctEntry = (Map.Entry)acctIter.next();
/* 302 */           String acctId = (String)acctEntry.getKey();
/* 303 */           List<Integer> folderIds = (List)acctEntry.getValue();
/*     */           
/*     */ 
/* 306 */           ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, zsc.wantsUnqualifiedIds());
/*     */           
/* 308 */           for (Iterator<Integer> iterFolderId = folderIds.iterator(); iterFolderId.hasNext();) {
/* 309 */             int folderId = ((Integer)iterFolderId.next()).intValue();
/*     */             try {
/* 311 */               CalSummaryCache.CalendarDataResult result = calCache.getCalendarSummary(octxt, acctId, folderId, type, rangeStart, rangeEnd, true);
/*     */               
/* 313 */               if (result != null)
/*     */               {
/* 315 */                 iterFolderId.remove();
/* 316 */                 addCalendarDataToResponse(parent, zsc, ifmt, result.data, result.allowPrivateAccess);
/*     */               }
/*     */             } catch (ServiceException e) {
/* 319 */               String ecode = e.getCode();
/* 320 */               if (ecode.equals("service.PERM_DENIED"))
/*     */               {
/* 322 */                 ZimbraLog.calendar.warn("Ignoring permission error during calendar search of folder %s", ifmt.formatItemId(folderId), e);
/*     */               }
/* 324 */               else if (ecode.equals("mail.NO_SUCH_FOLDER"))
/*     */               {
/* 326 */                 ZimbraLog.calendar.warn("Ignoring deleted calendar folder %s", new Object[] { ifmt.formatItemId(folderId) });
/*     */               }
/*     */               else
/* 329 */                 throw e;
/*     */             }
/* 331 */             iterFolderId.remove();
/*     */           }
/*     */           
/* 334 */           if (folderIds.isEmpty())
/* 335 */             acctIter.remove();
/*     */         }
/* 337 */         if (accountFolders.isEmpty()) {
/* 338 */           serverIter.remove();
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 343 */     for (Map.Entry<Server, Map<String, List<Integer>>> serverMapEntry : groupedByServer.entrySet()) {
/* 344 */       Server server = (Server)serverMapEntry.getKey();
/* 345 */       Map<String, List<Integer>> accountFolders = (Map)serverMapEntry.getValue();
/* 346 */       if (server.equals(localServer))
/* 347 */         for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
/* 348 */           String acctId = (String)entry.getKey();
/* 349 */           List<Integer> folderIds = (List)entry.getValue();
/* 350 */           if (!folderIds.isEmpty())
/*     */           {
/* 352 */             Account targetAcct = prov.get(Key.AccountBy.id, acctId);
/* 353 */             if (targetAcct == null) {
/* 354 */               ZimbraLog.calendar.warn("Skipping unknown account " + acctId + " during calendar search");
/*     */             }
/*     */             else {
/* 357 */               Mailbox targetMbox = mboxMgr.getMailboxByAccount(targetAcct);
/* 358 */               searchLocalAccountCalendars(parent, params, octxt, zsc, authAcct, targetMbox, folderIds, type);
/*     */             }
/*     */           }
/* 361 */         } else searchRemoteAccountCalendars(parent, params, zsc, authAcct, accountFolders);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void addCalendarDataToResponse(Element parent, ZimbraSoapContext zsc, ItemIdFormatter ifmt, CalendarData calData, boolean allowPrivateAccess)
/*     */     throws ServiceException
/*     */   {
/* 368 */     for (Iterator<CalendarItemData> itemIter = calData.calendarItemIterator(); itemIter.hasNext();) {
/* 369 */       CalendarItemData calItemData = (CalendarItemData)itemIter.next();
/* 370 */       int numInstances = calItemData.getNumInstances();
/* 371 */       if (numInstances > 0) {
/* 372 */         Element calItemElem = CacheToXML.encodeCalendarItemData(zsc, ifmt, calItemData, allowPrivateAccess, false);
/*     */         
/* 374 */         parent.addElement(calItemElem);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private static void searchLocalAccountCalendars(Element parent, SearchParams params, OperationContext octxt, ZimbraSoapContext zsc, Account authAcct, Mailbox targetMbox, List<Integer> folderIds, MailItem.Type type)
/*     */     throws ServiceException
/*     */   {
/* 382 */     ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), targetMbox.getAccountId(), false);
/* 383 */     long rangeStart = params.getCalItemExpandStart();
/* 384 */     long rangeEnd = params.getCalItemExpandEnd();
/* 385 */     for (Iterator i$ = folderIds.iterator(); i$.hasNext();) { int folderId = ((Integer)i$.next()).intValue();
/*     */       try {
/* 387 */         CalSummaryCache.CalendarDataResult result = targetMbox.getCalendarSummaryForRange(octxt, folderId, type, rangeStart, rangeEnd);
/*     */         
/* 389 */         if (result != null) {
/* 390 */           addCalendarDataToResponse(parent, zsc, ifmt, result.data, result.allowPrivateAccess);
/*     */         }
/*     */       } catch (ServiceException e) {
/* 393 */         String ecode = e.getCode();
/* 394 */         if (ecode.equals("service.PERM_DENIED"))
/*     */         {
/* 396 */           ZimbraLog.calendar.warn("Ignoring permission error during calendar search of folder " + ifmt.formatItemId(folderId), e);
/*     */         }
/* 398 */         else if (ecode.equals("mail.NO_SUCH_FOLDER"))
/*     */         {
/* 400 */           ZimbraLog.calendar.warn("Ignoring deleted calendar folder " + ifmt.formatItemId(folderId));
/*     */         }
/*     */         else {
/* 403 */           throw e;
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   private static void searchRemoteAccountCalendars(Element parent, SearchParams params, ZimbraSoapContext zsc, Account authAcct, Map<String, List<Integer>> accountFolders)
/*     */     throws ServiceException
/*     */   {
/* 413 */     String nominalTargetAcctId = null;
/* 414 */     StringBuilder queryStr = new StringBuilder();
/* 415 */     for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
/* 416 */       String acctId = (String)entry.getKey();
/* 417 */       if (nominalTargetAcctId == null)
/* 418 */         nominalTargetAcctId = acctId;
/* 419 */       ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
/* 420 */       List<Integer> folderIds = (List)entry.getValue();
/* 421 */       for (i$ = folderIds.iterator(); i$.hasNext();) { int folderId = ((Integer)i$.next()).intValue();
/* 422 */         if (queryStr.length() > 0) {
/* 423 */           queryStr.append(" OR ");
/*     */         }
/* 425 */         queryStr.append("inid:\"").append(ifmt.formatItemId(folderId)).append("\""); } }
/*     */     ItemIdFormatter ifmt;
/*     */     Iterator i$;
/* 428 */     Element req = zsc.createElement(MailConstants.SEARCH_REQUEST);
/* 429 */     req.addAttribute("types", MailItem.Type.toString(params.getTypes()));
/* 430 */     if (params.getSortBy() != null) {
/* 431 */       req.addAttribute("sortBy", params.getSortBy().toString());
/*     */     }
/* 433 */     req.addAttribute("offset", params.getOffset());
/* 434 */     if (params.getLimit() != 0)
/* 435 */       req.addAttribute("limit", params.getLimit());
/* 436 */     req.addAttribute("calExpandInstStart", params.getCalItemExpandStart());
/* 437 */     req.addAttribute("calExpandInstEnd", params.getCalItemExpandEnd());
/* 438 */     req.addAttribute("query", queryStr.toString(), Element.Disposition.CONTENT);
/*     */     
/* 440 */     Account target = Provisioning.getInstance().get(Key.AccountBy.id, nominalTargetAcctId);
/* 441 */     AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
/* 442 */     String pxyAuthToken = authToken.getProxyAuthToken();
/* 443 */     ZAuthToken zat = pxyAuthToken == null ? authToken.toZAuthToken() : new ZAuthToken(pxyAuthToken);
/* 444 */     ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
/* 445 */     zoptions.setTargetAccount(nominalTargetAcctId);
/* 446 */     zoptions.setTargetAccountBy(Key.AccountBy.id);
/* 447 */     zoptions.setNoSession(true);
/* 448 */     ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
/*     */     
/* 450 */     Element resp = zmbx.invoke(req);
/* 451 */     for (Element hit : resp.listElements()) {
/* 452 */       hit.detach();
/* 453 */       parent.addElement(hit);
/*     */     }
/*     */   }
/*     */   
/*     */   static Map<Server, Map<String, List<Integer>>> groupByServer(Map<String, List<Integer>> acctFolders)
/*     */     throws ServiceException
/*     */   {
/* 460 */     Map<Server, Map<String, List<Integer>>> groupedByServer = new HashMap();
/*     */     
/* 462 */     Provisioning prov = Provisioning.getInstance();
/* 463 */     for (Map.Entry<String, List<Integer>> entry : acctFolders.entrySet()) {
/* 464 */       String acctId = (String)entry.getKey();
/* 465 */       List<Integer> folderIds = (List)entry.getValue();
/* 466 */       Account acct = prov.get(Key.AccountBy.id, acctId);
/* 467 */       if (acct == null) {
/* 468 */         ZimbraLog.calendar.warn("Skipping unknown account " + acctId + " during calendar search");
/*     */       }
/*     */       else {
/* 471 */         Server server = prov.getServer(acct);
/* 472 */         if (server == null) {
/* 473 */           ZimbraLog.calendar.warn("Skipping account " + acctId + " during calendar search because its home server is unknown");
/*     */         }
/*     */         else {
/* 476 */           Map<String, List<Integer>> map = (Map)groupedByServer.get(server);
/* 477 */           if (map == null) {
/* 478 */             map = new HashMap();
/* 479 */             groupedByServer.put(server, map);
/*     */           }
/* 481 */           map.put(acctId, folderIds);
/*     */         } } }
/* 483 */     return groupedByServer;
/*     */   }
/*     */   
/*     */   private static void fixBooleanRecipients(Element request) {
/* 487 */     String recipField = "recip";
/*     */     String recip;
/*     */     try {
/* 490 */       recip = request.getAttribute(recipField);
/*     */     }
/*     */     catch (ServiceException e) {
/* 493 */       return;
/*     */     }
/* 495 */     if (recip.equals("true")) {
/* 496 */       request.addAttribute(recipField, "1");
/* 497 */     } else if (recip.equals("false")) {
/* 498 */       request.addAttribute(recipField, "0");
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/Search.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */